<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // Object.is(value1, value2) 判断两个值是否相等
    console.log(Object.is(1, 1));
    console.log(Object.is(1, "1"));
    console.log(Object.is(NaN, NaN));
    console.log(Object.is(+0, -0));
    // true false true false   


    // 2. Object.assign(target, ...sources) 对象的合并
    console.log(Object.assign({}, { a: 1 }, { a: 2 })); // { a: 2 }
    const config1 = {
        host: 'localhost',
        port: 8080,
        name: 'mortal',
        test: 'test'
    }
    const config2 = {
        host: 'www.baidu.com',
        port: 8081,
        name: 'mortal'
    }
    // { host: 'www.baidu.com', port: 8081, name: 'mortal', test: 'test' }
    console.log(Object.assign(config1, config2));

    // 3.Object.setPrototypeOf(config1, config2); Object.getPrototypeOf(config1);
    // 设置原型对象
    const school = {
        name: 'mortal',
        test: 'test'
    }
    const cities = {
        xiaoqu: ['北京', '上海', '广州']
    }

    console.log(Object.setPrototypeOf(school, cities));
    console.log(school);
    console.log(Object.getPrototypeOf(school));

    // es8对象方法扩展
    // 4.Object.keys values entries
    let data = {
        name: 'mortal',
        age: 18,
        sex: 'man'
    }
    console.log(Object.keys(data));
    console.log(Object.values(data));
    //entries 返回的是一个数组，数组的元素是数组，数组的第一个元素是键，第二个元素是值
    console.log(Object.entries(data));
    // map 将对象转化成map对象
    let map = new Map(Object.entries(data));
    console.log(map, map.get('name'));

    // 5.对象属性的描述对象 Object.getOwnPropertyDescriptor(obj,key)
    console.log(Object.getOwnPropertyDescriptors(data));
    console.log(Object.getOwnPropertyDescriptor(data, 'name'));

    let obj = Object.create(null, {
        name: {
            value: 'nanfeng',
            writable: true,
            enumerable: true,
            configurable: true
        }
    });
    // 返回的结果就是上面Object.create(null, {})创建的对象
    console.log(Object.getOwnPropertyDescriptors(obj));

    // es10 Object.fromEntries 将entries二维数组/map对象转换为对象
    // 与Object.entries相反

    const result = Object.fromEntries([
        ['name', 'nanfeng'],
        ['age', 18]
    ]);
    console.log(result);

    const map1 = new Map();
    map1.set('name', 'nanfeng');
    map1.set('age', 18);
    const result2 = Object.fromEntries(map1);
    console.log(result2);

</script>

</html>